#!/bin/bash
if [ ! -f "ILSVRC2012_img_train.tar" ];then
echo "ILSVRC2012_img_train.tar no exist"
exit
fi
if [ ! -f "ILSVRC2012_img_val.tar" ];then
echo "ILSVRC2012_img_val.tar no exist"
exit
fi
if [ -d "./train" ];then
rm -rf ./train
fi
if [ -d "./val" ];then
rm -rf ./val
fi

mkdir -p train val 
tar -xvf ILSVRC2012_img_train.tar -C train/
tar -xvf ILSVRC2012_img_val.tar -C val/
cd train/
find . -name "*.tar" | while read LINE ; do mkdir -p "${LINE%.tar}"; tar -xvf "${LINE}" -C "${LINE%.tar}"; rm -f "${LINE}"; done
cd ..
if [ -d "simple_imagenet_preprocess" ];then
python3 simple_imagenet_preprocess/preprocess_imagenet_validation_data.py val/ simple_imagenet_preprocess/imagenet_2012_validation_synset_labels.txt
else
python3 simple_imagenet_preprocess-master/preprocess_imagenet_validation_data.py val/ simple_imagenet_preprocess-master/imagenet_2012_validation_synset_labels.txt
fi